<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jualbeli extends CI_Controller {
    function __construct()
    {
        parent::__construct();
		$this->load->helper(array('url','form'));
        $this->load->library(array('pagination','image_lib'));
		$this->load->database();
        $this->load->model(array('header','m_bengkel','m_barang','m_data_kendaraan','m_rute',
                                 'm_iklan','m_kategori','m_komentar','m_private_message','m_sosmed'));
    }
    
    function _view( $template = '', $param = ''){
        $params['nama'] = $this->header->get_kategori();        
        $this->load->view('header',$params);
        $this->load->view($template, $param);
        $this->load->view('footer');
    }
    
	public function index()
	{
		$params['data'] = $this->m_barang->get_last_post();
		$this->_view('v_barang_last_post',$params);
	}

//---------------TAMPIL VIEW----------------
    public function inpt_bengkel()
    { 
        $this->_view('v_bengkel_input');
    }
    public function inpt_barang()
    {
        $params['nama'] = $this->m_kategori->get_kategori_jb();
        $params['id'] = $this->m_barang->get_last_id();
        $this->_view('v_barang_input',$params);
    }
    public function inpt_data_kendaraan()
    {
        $this->_view('v_data_kendaraan_input');
    }
    public function inpt_iklan()
    {
        $params['nama'] = $this->m_kategori->get_kategori_iklan();
        $params['id'] = $this->m_iklan->get_last_id();
        $this->_view('v_iklan_input',$params);
    }
    public function inpt_kategori_iklan()
    {
        $this->_view('v_kategori_input_iklan');
    }
    public function inpt_kategori_jb()
    {
        $this->_view('v_kategori_input_jb');
    }
    public function inpt_private_message()
    {
        $this->_view('v_private_message_input');
    }
    public function inpt_rute()
    {
        $this->_view('v_rute_input');
    }

//---------------BENGKEL----------------
    public function input_bengkel()
    {
        $this->m_bengkel->input_bengkel();
        redirect('jualbeli/show_bengkel');
    }
    
    public function data_edit_bengkel($id = '')
    {
        $params['data'] = $this->m_bengkel->get_id_bengkel($id);
        $this->_view('v_bengkel_edit',$params);
    }
    
    public function edit_bengkel()
    {
        $this->m_bengkel->edit_bengkel();
        redirect('jualbeli/show_bengkel');
    }
    
    public function show_bengkel()
    {
        $params['data'] = $this->m_bengkel->get_bengkel();
        $this->_view('v_bengkel_show',$params);
    }
    
//---------------BARANG----------------

    public function cari_barang()
    {
        $params['data'] = $this->m_barang->cari_barang();
        $this->_view('v_search',$params);
    }
    
    public function data_edit_barang($id = '')
    {
        $params['data'] = $this->m_barang->get_id_barang($id);
        $this->_view('v_barang_edit',$params);
    }
    
    public function edit_barang()
    {
        $this->m_barang->edit_barang();
        redirect('jualbeli/show_barang');
    }
    
    public function input_barang()
    {
        $config['upload_path'] = './upload/barang/';
	    $config['allowed_types'] = 'gif|jpg|png';
        $config['max_width'] = '320';
        $config['max_height'] = '250';
        $config['file_name']    = 'barang_'.$this->input->post('id');
        $this->load->library('upload', $config);
        
        $this->upload->do_upload('gambar1');        
        
        $this->m_barang->input_barang();
        redirect('jualbeli/show_barang');;
    }
    
    public function show_barang()
    {
        $params['data'] = $this->m_barang->get_barang();
        $this->_view('v_barang_show',$params);
    }
    
    public function detail_barang($id = '')
    {
        $params['komen'] = $this->m_komentar->get_komentar($id);
        $params['data'] = $this->m_barang->detail_barang($id);
        $params['id'] = $id;
        $this->_view('v_barang_detail',$params);
    }
    
    public function last_post(){
        $params['data']   = $this->m_barang->get_last_post();
        $params['gambar'] = $this->m_iklan->get_last_id();
        $this->_view('v_barang_last_post',$params);
    }
//---------------DATA KENDARAAN----------------  
    public function input_data_kendaraan()
    {
        $this->m_data_kendaraan->input_data_kendaraan();
        redirect('jualbeli/show_data_kendaraan');
    }
    
    public function show_data_kendaraan()
    {
        $params['data'] = $this->m_data_kendaraan->get_data_kendaraan();
        $this->_view('v_data_kendaraan_show',$params);        
    }
    
    public function data_edit_data_kendaraan($id = '')
    {
        $params['data'] = $this->m_data_kendaraan->get_id_data_kendaraan($id);
        $this->_view('v_data_kendaraan_edit',$params);
    }
    
    public function edit_data_kendaraan()
    {
        $this->m_data_kendaraan->edit_data_kendaraan();
        redirect('jualbeli/show_data_kendaraan');
    }
    
//---------------IKLAN----------------
    public function input_iklan()
    {
        $this->m_iklan->input_iklan();
        redirect('jualbeli/show_iklan');
    }    
    
    public function show_iklan()
    {
        $params['data']=$this->m_iklan->get_iklan();
        $this->_view('v_iklan_show',$params);
    }
    
    public function last_post_iklan()
    {
        $params['data'] = $this->m_iklan->get_last_post();
        $this->_view();        
    }
    
    public function data_edit_iklan($id = '')
    {
        $params['data'] = $this->m_iklan->get_id_iklan($id);
        $params['kategori'] = $this->m_kategori->get_kategori_iklan();
        $this->_view('v_iklan_edit',$params);
    }
    public function edit_iklan()
    {
        $this->m_iklan->edit_iklan();
        redirect('jualbeli/show_iklan');
    }
//---------------KATEGORI----------------
    public function input_kategori()
    {
        $this->m_kategori->input_kategori_iklan();
        redirect('jualbeli/show_kategori');
    }    
    
//---------------KOMENTAR----------------
    public function input_komentar($id = '')
    {
        $this->m_komentar->input_komentar($id);
        redirect('jualbeli/detail_barang/'.$id);
    }
    
//---------------PRIVATE MESSAGE---------------- 
    public function input_private_message()
    {
        $this->m_private_message->input_private_message();
        $this->_view('v_private_message');
    }
   
//---------------SOSIAL MEDIA----------------
    public function input_sosmed()
    {
        $this->m_sosmed->input_sosmed();
        $this->_view('v_sosmed_show');
    }
    
//---------------RUTE----------------
    public function show_rute()
    {
        $params['data'] = $this->m_rute->get_rute();
        $this->_view('v_rute_show',$params);
    }
    
    public function input_rute()
    {
        $this->m_rute->input_rute();
        redirect('jualbeli/show_rute');
    }
}